package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Detail;
import com.example.springboot.mapper.DetailMapper;
import com.example.springboot.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.spring.web.json.Json;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/detail")
public class DetailController {
    @Autowired
    private DetailMapper detailMapper;
    @Autowired
    private DetailService detailService;
    @GetMapping
    public Result findAll(){
        return Result.success(detailMapper.findAll());
    }
    @PostMapping("/create")
    public Result create(@RequestBody DetailDTO detailDTO) throws Exception {
        return Result.success(detailService.create(detailDTO));
    }
    @DeleteMapping("/{did}")
    public Result deleteByDid(@PathVariable Long did){
        return Result.success(detailMapper.deleteByDid(did));
    }
    @GetMapping("/findbydid")
    public Result findByDid(@RequestParam Long did){
        List<Detail> one=detailMapper.findByDid(did);
        return Result.success(one);
    }
}
